package com.woniuxy.micromemberserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.micromemberserver.bean.MemberBean;
import com.woniuxy.micromemberserver.bean.PageRequest;
import com.woniuxy.micromemberserver.mapper.MemberMapper;
import com.woniuxy.micromemberserver.service.IMemberService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 会员业务层实现类
 * @Author hz
 */
@Transactional(readOnly = true)
@Service
public class MemberServiceImpl implements IMemberService {

    @Resource
    private MemberMapper memberMapper;

    /**
     * 新增会员
     * @param memberBean
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public int saveMember(MemberBean memberBean) {
        return memberMapper.saveMember(memberBean);
    }

    /**
     * 条件分页查询
     * @param request 分页请求
     * @param memberBean 会员实体
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public PageInfo<MemberBean> findAllByParams(PageRequest request, MemberBean memberBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).doSelectPageInfo(()->
                memberMapper.findAllByParams(request,memberBean)
        );
    }

    /**
     * 修改会员（或删除：仅修改删除标记）
     * @param memberBean
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public int updateMember(MemberBean memberBean) {
        return memberMapper.updateMember(memberBean);
    }

}
